package com.wyq.expression;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component("ex")
public class SGEExpressionRoot {
    public final boolean hasAuthority(String authority) {
        if(authority == null){
            return false;
        }
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        for(GrantedAuthority g : authorities){
            if (authority.equals(g.getAuthority())){
                return true;
            }
        }
        return false;
    }
}
